package bookez.model.service.impl;

import java.util.List;

import bookez.model.businessobject.BusType;
import bookez.model.dao.BusTypeDao;
import bookez.model.exception.BusinessLogicLayerException;
import bookez.model.exception.DataAccessLayerException;
import bookez.model.service.BusTypeService;
import bookez.model.service.GenericService;

public class BusTypeServiceImpl extends GenericService<BusTypeDao>
implements BusTypeService {

	@Override
	public List<BusType> getAllBusType() throws BusinessLogicLayerException {
		List<BusType> result = null;
		
		try {
			result = getDao().findAll();
		}//end try
		
		catch( DataAccessLayerException dalEx ) {
			throw new BusinessLogicLayerException( dalEx );
		}//end catch
		
		return result;
	}//end method getAllBusType

	@Override
	public BusType getBusTypeById(Long id) throws BusinessLogicLayerException {
		// TODO Auto-generated method stub
		BusType result = null;
		
		try {
			result = getDao().read( id );
		}//end try
		
		catch( DataAccessLayerException dalEx ) {
			throw new BusinessLogicLayerException( dalEx );
		}//end catch
		
		return result;
	}//end method getBusTypeById

	@Override
	public boolean saveBusType(BusType type) throws BusinessLogicLayerException {
		// TODO Auto-generated method stub
		boolean result = true;
		
		try {
			getDao().update( type );
		}//end try
		
		catch( DataAccessLayerException dalEx ) {
			result = false;
			throw new BusinessLogicLayerException( dalEx );
		}//end catch
		
		return result;
	}//end method saveBusType

	@Override
	public boolean createBusType(BusType type) throws BusinessLogicLayerException {
		// TODO Auto-generated method stub
		boolean result = true;
			
		try {
			Long generatedId = getDao().create( type );
			type.setId( generatedId );
		}
		catch ( DataAccessLayerException dalEx ) {
			result = false;
			throw new BusinessLogicLayerException( dalEx );
		}
		
		return result;
	}//end method createBusType

	@Override
	public BusType getBusTypeByName(String name)
			throws BusinessLogicLayerException {
		// TODO Auto-generated method stub
		BusType result = null;
		
		try {
			result = getDao().findByName( name );
		}//end try
		
		catch( DataAccessLayerException dalEx ) {
			throw new BusinessLogicLayerException( dalEx );
		}//end catch
		
		return result;
	}//end method getBusTypeByName
	
}//end class BusServiceImpl
